package com.liusuai.yixian.update;

import com.alibaba.fastjson.JSONObject;
import com.liusuai.yixian.utils.JsonResourceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@RestController
public class UpdateControler {

    private static Logger logger = LoggerFactory.getLogger(UpdateControler.class);

    @ResponseBody
    @RequestMapping(value = "/update"
            , method = RequestMethod.POST
            , produces = "application/json;charset=UTF-8")
    public JSONObject update(@RequestBody JSONObject json) {
        if (json != null)
            System.out.print("updateLoginId:  " + json.toJSONString());
        JSONObject object = new JSONObject();
        object.put("version", "1");
        object.put("url", "");
        return object;
    }


    //获取新版本的数据
    @RequestMapping(value = {"/getNewVersionInfo"}
            , method = {RequestMethod.POST}
            , produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Object getNewVersionInfo(HttpServletRequest request, HttpServletResponse response) {
        logger.info("/getNewVersionInfo" + request.getQueryString());

        return JsonResourceUtils.getJsonObjFromResource("/static/json/app_version_info.json");
    }

}

